#pragma once
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdarg>
#include <ctime>

#define DEBUG 0
#define NORMAL 1
#define WARING 2
#define ERROR 3
#define FATAL 4
#define LOGFILE "./calculator.log"

const char* gLevelMap[]={"DEBUG","NORMAL","WARING","ERROR","FATAL"};

//完整的日志功能，至少: 日志等级 时间 支持用户自定义(日志内容, 文件行，文件名)
void logMessage(int level,const char* format,...)
{
    //if(level==0) printf("正确");
    char stdBuff[10024];
    time_t timestamp = time(nullptr);//时间
    snprintf(stdBuff,sizeof(stdBuff),"[%s] [%ld] ", gLevelMap[level], timestamp);

    char logBuff[1024]; //自定义部分
    // va_list args;
    // va_start(args, format);
    // // vprintf(format, args);
    // vsnprintf(logBuffer, sizeof logBuffer, format, args);
    // va_end(args);

    snprintf(logBuff,sizeof(logBuff),"[%s] [%ld] ", gLevelMap[level], timestamp);
    

    FILE *fp = fopen(LOGFILE, "a");
    // printf("%s%s\n", stdBuffer, logBuffer);
    fprintf(fp, "%s %s\n", stdBuff, logBuff);
    fclose(fp);
}


